import {_decorator, Node, Prefab, instantiate} from 'cc';
import {SceneManager} from 'db://assets/Scripts/Scene/SceneManager';
import DataManager from "db://assets/Scripts/Runtime/DataManager";
import {ItemStatusEnum, ItemTypeEnum, SceneEnum} from "db://assets/Scripts/Enum";

const {ccclass, property} = _decorator;


@ccclass('H4SceneManager')
export class H4SceneManager extends SceneManager {

    @property(Prefab)
    mailPrefab: Prefab = null

    @property(Node)
    mailPlaceholder: Node = null

    type: SceneEnum = SceneEnum.H4

    render() {
        super.render()
        this.items.destroyAllChildren()

        const mail = DataManager.Instance.items.find(i => i.type === ItemTypeEnum.Mail)
        if (mail && mail.status === ItemStatusEnum.Scene) {
            const mailNode = instantiate(this.mailPrefab)
            this.items.addChild(mailNode)
            mailNode.setPosition(this.mailPlaceholder.position)
        }
    }
}

